package net.core.base.bean;

import java.util.List;

public class Page {
	/**
	 * 当前页号, 采用自然数计数 1,2,3,...
	 */
	private int num;
	/**
	 * 页面大小:一个页面显示多少个数据
	 */
	private int size;
	/**
	 * 数据总数：一共有多少个数据
	 */
	private int rowCount;
	/**
	 * 页面总数
	 */
	private int pageCount;
	/**
	 * 当前页面开始行, 第一行是0行
	 */
	private int startRow;
	/**
	 * 第一页 页号
	 */
	private int first = 1;
	/**
	 * 最后页 页号
	 */
	private int last;
	/**
	 * 下一页 页号
	 */
	private int next;
	/**
	 * 前页 页号
	 */
	private int prev;
	/**
	 * 页号式导航, 起始页号
	 */
	private int start;
	/**
	 * 页号式导航, 结束页号
	 */
	private int end;
	/**
	 * 页号式导航,最多显示页号数量为numCount+1;这里显示11页。
	 */
	private int numCount = 10;

	/**
	 * 总共多少页
	 */
	private int count;

	// 
	@SuppressWarnings("unchecked")
	private List list;// 结果集

	// ------------------------------
	public int getNum() {
		return num;
	}

	public void setNum(int num) {
		this.num = num;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public int getRowCount() {
		return rowCount;
	}

	public void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}

	@SuppressWarnings("unchecked")
	public List getList() {
		return list;
	}

	@SuppressWarnings("unchecked")
	public void setList(List list) {
		this.list = list;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getStartRow() {
		return startRow;
	}

	public void setStartRow(int startRow) {
		this.startRow = startRow;
	}

	public int getFirst() {
		return first;
	}

	public void setFirst(int first) {
		this.first = first;
	}

	public int getLast() {
		return last;
	}

	public void setLast(int last) {
		this.last = last;
	}

	public int getNext() {
		return next;
	}

	public void setNext(int next) {
		this.next = next;
	}

	public int getPrev() {
		return prev;
	}

	public void setPrev(int prev) {
		this.prev = prev;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getEnd() {
		return end;
	}

	public void setEnd(int end) {
		this.end = end;
	}

	public int getNumCount() {
		return numCount;
	}

	public void setNumCount(int numCount) {
		this.numCount = numCount;
	}

	/**
	 * 
	 * @param size
	 *            一个页面显示多少个数据
	 * @param pn
	 *            第几页
	 * @param rowCount
	 *            总的记录数
	 */
	public Page(int size, int pn, int rowCount) {
		this.num = pn; // 当前第几页
		this.size = size; // 每页的大小
		this.rowCount = rowCount; // 总记录数
		this.pageCount = (int) Math.ceil((double) rowCount / size);
		this.count = this.pageCount;
		this.num = Math.min(this.num, pageCount);
		this.num = Math.max(1, this.num);

		this.startRow = (this.num - 1) * size;
		this.last = this.pageCount;
		this.next = Math.min(this.pageCount, this.num + 1);
		this.prev = Math.max(1, this.num - 1);

		// 计算page 控制
		start = Math.max(this.num - numCount / 2, first);
		end = Math.min(start + numCount, last);
		if (end - start < numCount) {
			start = Math.max(end - numCount, 1);
		}
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

}
